<?php 
header('content-type:text/html;charset=utf8');
$pdo = new PDO('mysql:host=127.0.0.1;dbname=month8;charset=utf8');
$redis = new redis();
$redis->connect('127.0.0.1','6379');

$page = isset($_GET['page']) ?$_GET['page']:1;
$sql = "SELECT count(*) from weather";
$res =  $pdo->query($sql)->fetch();
$pagenum = $res['count(*)'];

$pagesize = 3;
$totalpage = ceil($pagenum/$pagesize);
$limit = ($page-1)*$pagesize;

if($redis->get('data'.$page)){
	echo "这是redis";
	$data = $redis->get('data'.$page);
	$data =  json_decode($data,true);
}else{
	$sql  =  "SELECT * FROM weather limit $limit,$pagesize";
	$data = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
	$redisata = json_encode($data);
	$redis->set('data'.$Page,$redisdata);
}

$pre =  $page-1>0 ? $Page-1:1;
$next = $Page+1>$totalpage ? $totalpage :$page+1;
$str = "<a href='page.php?page=1'>首页</a><a href='page.php?page=$pre'>上一页</a><a href='page.php?page=$next>下一页</a><a href='page.php?page=$totalpage'>尾页</a>";
 ?>
 <!DOCTYPE html>
 <html lang="en">
 <head>
 	<meta charset="UTF-8">
 	<title>Document</title>
 </head>
 <body>
 	<table>
 		<tbody>
 			<tr>
 				<td>商品名</td>
 				<td>价格</td>
 				<td>数量</td>
 				<td>操作</td>
 			</tr>
 			<?php foreach ($data as $key => $value): ?>
 				<tr>
	 				<td><?php $value['name'];?></td>
	 				<td><?php $value['money'];?></td>
	 				<td>100</td>
	 				<td><a href="detail.php?id=<?php echo $value['id']?>"><input type="button" value="详情"></a></td>
	 			</tr>
 			<?php endforeach ?>
 		</tbody>
 	</table><?php echo $str;?>
 </body>
 </html>